package com.hpq.chat.service.srategy.msg;

import com.hpq.chat.dao.MessageDAO;
import com.hpq.chat.domain.enums.MessageTypeEnum;
import com.hpq.chat.domain.model.Message;
import com.hpq.chat.domain.model.msg.FileMsgDTO;
import com.hpq.chat.domain.model.msg.MessageExtra;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Optional;

/**
 * 文件消息
 */
@Component
public class FileMsgHandler extends AbstractMsgHandler<FileMsgDTO> {
    @Autowired
    private MessageDAO messageDao;
    @Override
    MessageTypeEnum getMsgTypeEnum() {
        return MessageTypeEnum.FILE;
    }

    @Override
    protected void saveMsg(Message message, FileMsgDTO body) {
        MessageExtra extra = Optional.ofNullable(message.getExtra()).orElse(new MessageExtra());
        Message msg = new Message();
        msg.setId(message.getId());
        msg.setExtra(extra);
        extra.setFileMsg(body);
        messageDao.updateById(msg);
    }

    @Override
    public Object showMsg(Message msg) {
        return msg.getExtra().getFileMsg();
    }

    @Override
    public Object showReplyMsg(Message msg) {
        return "文件";
    }

    @Override
    public String showContactMsg(Message msg) {
        return "[文件]";
    }
}
